package com.ql.controller;

import com.ql.domain.response.JsonResult;
import com.ql.domain.response.MenuNode;
import com.ql.domain.Project;
import com.ql.domain.UserInfo;
import com.ql.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    IUserService userService;


    @RequestMapping("/findAll.do")
    @ResponseBody
    public JsonResult findAll(String name, @RequestParam(name = "page", required = true, defaultValue = "1") Integer page, @RequestParam(name = "limit", required = true, defaultValue = "10") Integer limit) {
        return userService.findAll(name, page, limit);
    }

    @RequestMapping("/save.do")
    @ResponseBody
    public JsonResult save(UserInfo userInfo) {
        return userService.save(userInfo);
    }

    @RequestMapping("/update.do")
    @ResponseBody
    public JsonResult update(UserInfo userInfo) {
        return userService.update(userInfo);
    }

    @RequestMapping("/del.do")
    @ResponseBody
    public JsonResult del(Integer id) {
        return userService.del(id);
    }

    @RequestMapping("/getMenuPower.do")
    @ResponseBody
    public List<MenuNode> getMenuPower(Integer id) {
        return userService.getMenuPower(id);
    }

    @RequestMapping("/userCorrelationMenu.do")
    @ResponseBody
    public JsonResult userCorrelationMenu(Integer[] menuIds,Integer userId) {
        return userService.userCorrelationMenu(menuIds,userId);
    }

    @RequestMapping("/getPermissionPower.do")
    @ResponseBody
    public List<Integer> gePermissionPower(String userId) {
        return userService.getPermissionPower(userId);
    }

    @RequestMapping("/userCorrelationPermission.do")
    @ResponseBody
    public JsonResult userCorrelationPermission(String[] permissionIds,String userId) {
        return userService.userCorrelationPermission(permissionIds,userId);
    }
    @RequestMapping("/getSectionPower.do")
    @ResponseBody
    public  List<Project> getSectionPower(String id){
        return userService.getSectionPower(id);
    }
    @RequestMapping("/userCorrelationSection.do")
    @ResponseBody
    public JsonResult userCorrelationSection(String[] sectionIds,String userId) {
        return userService.userCorrelationSection(sectionIds,userId);
    }
}
